package main.java.com.lee.pattern;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2022/2/17
 */
public class SingletonDemo {
    private SingletonDemo() {
    }
    private volatile SingletonDemo instance;
    public SingletonDemo getInstance() {
        if (instance == null) {
            synchronized (SingletonDemo.class) {
                if (instance == null) {
                    instance = new SingletonDemo();
                }
            }
        }
        return instance;
    }

    private static class LazyHolder {
        private static final SingletonDemo instance = new SingletonDemo();
    }

    public SingletonDemo getInstance2() {
        return LazyHolder.instance;
    }
}
